package com.sigmazero13.gameutils.utils;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.sigmazero13.gameutils.R;
import com.sigmazero13.gameutils.model.GameInfo;

public class GameNameAdapter extends ArrayAdapter<GameInfo> {

	private ArrayList<GameInfo> games;
	private Context mContext;
	
	public GameNameAdapter(Context context, int textViewResourceId, List<GameInfo> games) {
		super(context, textViewResourceId, games);
		mContext = context;
		this.games = new ArrayList<GameInfo>(games);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.list_item, null);
		}
		GameInfo game = games.get(position);
		if (game != null) {
			TextView list_item = (TextView)v.findViewById(R.id.list_item_text);
			if (list_item != null) {
				list_item.setTextColor(R.color.game_spinner_color);
				list_item.setText(game.getName());
			}
		}
		
		return v;
		
	}
	
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(android.R.layout.simple_spinner_dropdown_item, null);
		}
		GameInfo game = games.get(position);
		if (game != null) {
			TextView list_item = (TextView)v.findViewById(android.R.id.text1);
			if (list_item != null) {
				list_item.setText(game.getName());
			}
		}
		
		return v;
	}
}
